package com.itheima.json;

import com.alibaba.fastjson.JSON;
import com.itheima.fastjson.User;
import org.junit.Test;

import java.util.ArrayList;

public class test01 {

    @Test
    public void method01(){
        User user = new User("sc", "123");
        System.out.println(user.toJson());

    }


    @Test
    public void method2(){
        User user = new User("ww", "123");
        String json = JSON.toJSONString(user);
        System.out.println(json);
    }

    @Test
    public void method3(){
        User user = new User("ww", "123");
        ArrayList<User> list = new ArrayList<>();
        list.add(user);
        String json = JSON.toJSONString(list);
        System.out.println(json);

    }

    @Test
    public void method4(){
     String str="{\"password\":\"123\",\"username\":\"ww\"}";
        User user = JSON.parseObject(str, User.class);
        System.out.println(user);


    }


}
